



var reverse = function(x) {
    const min=-Math.pow(2,31)
    const max=Math.pow(2,31)-1
     let reverse=0
     let num=x
     while(num!==0)
     {
        const digit=num%10
        num=Math.trunc(num/10)
        if((reverse>Math.trunc(max/10))||(reverse===Math.trunc(max/10)&&digit>max%10))
        {
            return 0
        }
        if((reverse<Math.trunc(min/10))||reverse===Math.trunc(min/10)&&digit<min%10)
        {
            return 0
        }
        reverse=reverse*10+digit
     }
     return reverse
  
};